package io.zsy.consumer;

import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.cloud.stream.annotation.StreamListener;
import org.springframework.cloud.stream.messaging.Sink;
import org.springframework.cloud.stream.messaging.Source;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * 消息消费者工具类，通过调用该类的send方法向MQ消费
 * <p>
 * EnableBinding中的value值Sink，作用是将消息通道与配置文件中配置的交换机进行绑定
 *
 * @author: zhangshuaiyin
 * @date: 2021/12/22 20:36
 */
@Component
@EnableBinding(Sink.class)
public class MessageConsumer {

    /**
     * 接收消息
     *
     * @param message message
     */
    @StreamListener(Sink.INPUT)
    public void receive(String message) {
        System.out.println("从MQ中消费到消息：" + message);
    }

}
